package com.tanhua.server.controller;



import com.tanhua.server.service.SoundService;
import com.tanhua.server.vo.SoundVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("peachblossom")
public class SoundController {

    @Autowired
    private SoundService soundService;



    @PostMapping
    public ResponseEntity<Void> saveSound(@RequestParam(value = "soundFile",required = false)MultipartFile soundFile){

        try {
            String id=soundService.saveSound(soundFile);
            if(StringUtils.isNotEmpty(id)){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    @GetMapping
    public ResponseEntity<SoundVo> getSound(){
        try {
            SoundVo soundVo=soundService.getSound();
            if(null!=soundVo){
                return ResponseEntity.ok(soundVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}